exports.init= function(){};
var package = require("../package.json");
mongoskin = require('mongoskin');
var option = {  
    native_parser: true  
};  
exports.findOne=function(collection,query,callback){    
    var db= mongoskin.db(package.DataBase, option);     
    db.collection(collection).findOne(query, function(err, item){       
        if(err){
            return callback(false);
        }
        return callback(item);
    });
}
exports.find=function(collection,query,includeItem,sort,pageIndex,pageSize,callback){    
    if(includeItem==null)includeItem={};
    if(sort==null)sort={};
    var skipCount=(pageIndex-1)*pageSize;    
    var db= mongoskin.db(package.DataBase, option);     
    db.collection(collection).find(query,includeItem).sort(sort).skip(skipCount).limit(pageSize).toArray(function(err, items){
        if(err){
            return callback(false);
        }
        return callback(items);
              
    });
}

exports.create=function(collection,model,callback){    
    var db= mongoskin.db(package.DataBase, option);     
    db.collection(collection).save(model, function(err, item){
        if(err) {
            return callback(false);
        }        
        return callback(true);
    });
}

exports.update=function(collection,query,updateModel,callback){
    var db= mongoskin.db(package.DataBase, option);  
    var set={$set:updateModel}    
    db.collection(collection).update(query, set,{new:true,upset:true}, function(err){
         if(err) {
            return callback(false);
        }    
        return callback(true);
    });
}

exports.delete=function(collection,query,callback){
    var db= mongoskin.db(package.DataBase, option);     
    db.collection(collection).remove(query, function(err){
        if(err) {
            return callback(false);
        }       
        return callback(true);
    });
}
